package com.szy.mvp_demo.UI;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.szy.mvp_demo.Adapter.ItemMessageTypeAdapter;
import com.szy.mvp_demo.Entity.MessageTypeEntity;
import com.szy.mvp_demo.R;

import org.w3c.dom.ProcessingInstruction;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ListView listView;
    private ItemMessageTypeAdapter adapter;
    private Activity mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initview();
        initdata();
    }

    private void initview() {
        mContext = this;
        listView = findViewById(R.id.list_main);
        adapter = new ItemMessageTypeAdapter(this);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(onItemClickListener);
    }

    private void initdata() {
        List<MessageTypeEntity> data = new ArrayList<>();
        data.add(new MessageTypeEntity("头条", 0));
        data.add(new MessageTypeEntity("要闻", 1));
        data.add(new MessageTypeEntity("娱乐", 2));
        data.add(new MessageTypeEntity("财经", 3));
        data.add(new MessageTypeEntity("体育", 4));
        data.add(new MessageTypeEntity("科技", 5));
        data.add(new MessageTypeEntity("北京", 6));
        adapter.setdate(data);
    }

    private AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(mContext, MessageListActivity.class);
            MessageTypeEntity entity = adapter.getData().get(position);
            intent.putExtra("type", entity.getType());
            startActivity(intent);
        }
    };
}
